/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vision.IndexingImagenes;

import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import java.util.Comparator;

/**
 *
 * @author juanagva
 */
public class FrameBuscar extends javax.swing.JFrame {

    /**
     * Creates new form FrameBuscar
     */
     JFileChooser fc = new JFileChooser();
     String foto = new String();     
     
      ArrayList listaImagenes = new ArrayList();
      
    public FrameBuscar() {
        initComponents();
    }
    
    
      static List<String> lista = Arrays.asList("Auto Color Correlogram","CEDD Document","Color Histogram","Color Layout",
      "Default Document","Edge Histogram"
        ,"FastAutoColorCorrelation","FCTHD","GaborDocument","JCDDocument","JpegCoefficientHistogramDocument"  
        ,"ScalableColor","TamuraDocument");
   
    
   
    

    public void setjComboBox1(List<String> lista) 
    {
        this.jComboBox1.removeAllItems();
        for(String item : lista )
        {
           this.jComboBox1.addItem(item); 
        }
        
    }  
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton2 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jButton3 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jButton2.setText("jButton2");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Elegir la ubicacion de la imagen");

        jButton1.setText("Elegir");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel2.setText(" ");

        jButton3.setText("Analizar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jScrollPane2.setViewportView(jTextArea2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 397, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(60, 60, 60)
                        .addComponent(jButton3))
                    .addComponent(jLabel2)
                    .addComponent(jButton1)
                    .addComponent(jLabel1)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 434, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(51, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(22, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        
         int returnVal = fc.showOpenDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
             foto  = fc.getSelectedFile().toString();
             this.jLabel2.setText(foto);            
           
        } else {
            System.out.println("no se selecciono ningun directorio");
        }  
        
        this.setjComboBox1(lista);
        
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        
       
        ImagenBusqueda busqueda = new ImagenBusqueda();
        
         try 
         {
              FileInputStream imageStream = new FileInputStream(foto);
              BufferedImage bimg = ImageIO.read(imageStream);
        
             
                String opcion = this.jComboBox1.getSelectedItem().toString();
                if (opcion.equals("Auto Color Correlogram"))
                {
                    busqueda.setIndexPath("Auto-Color");
                      listaImagenes =  busqueda.DefaultImplementacion(bimg,"Auto Color Correlogram");
                }
                if (opcion.equals("CEDD Document"))
                {
                    busqueda.setIndexPath("CEDD-Document");
                      listaImagenes =  busqueda.DefaultImplementacion(bimg,"CEDD Document");
                }
                if (opcion.equals("Color Histogram"))
                {
                    busqueda.setIndexPath("Color-Histogram");
                      listaImagenes =  busqueda.DefaultImplementacion(bimg,"Color Histogram");
                }
                 if (opcion.equals("Color Layout"))
                {
                    busqueda.setIndexPath("Color-Layout");
                    listaImagenes = busqueda.DefaultImplementacion(bimg,"Color Layout");
                }
                  if (opcion.equals("Default Document"))
                {
                    busqueda.setIndexPath("Default-Document");
                     listaImagenes = busqueda.DefaultImplementacion(bimg,"Default Document");
                }
                   if (opcion.equals("Edge Histogram"))
                {
                    busqueda.setIndexPath("Edge-Histogram");
                      listaImagenes = busqueda.DefaultImplementacion(bimg,"Edge Histogram");
                } 
                 if (opcion.equals("FCTHD"))
                {
                     busqueda.setIndexPath("FCTHD");
                      listaImagenes =  busqueda.DefaultImplementacion(bimg,"FCTHD");
                } 
               
                 if (opcion.equals("GaborDocument"))
                {
                     busqueda.setIndexPath("GaborDocument");
                      listaImagenes =  busqueda.DefaultImplementacion(bimg,"GaborDocument");
                }   
                 if (opcion.equals("JCDDocument"))
                {
                    busqueda.setIndexPath("JCDDocument");
                     listaImagenes =   busqueda.DefaultImplementacion(bimg,"JCDDocument");
                }
                  if (opcion.equals("JpegCoefficientHistogramDocument"))
                {
                     busqueda.setIndexPath("JpegCoefficientHistogramDocument");
                     listaImagenes =   busqueda.DefaultImplementacion(bimg,"JpegCoefficientHistogramDocument");
                }
                   if (opcion.equals("ScalableColor"))
                {
                     busqueda.setIndexPath("ScalableColor");
                      listaImagenes =  busqueda.DefaultImplementacion(bimg,"ScalableColor");
                }
                   
                    if (opcion.equals("TamuraDocument"))
                {
                    busqueda.setIndexPath("TamuraDocument");
                     listaImagenes =   busqueda.DefaultImplementacion(bimg,"TamuraDocument");
                }
        } 
         catch (IOException ex) 
         {
                Logger.getLogger(FrameIndexing.class.getName()).log(Level.SEVERE, null, ex);
          }
        
         KnnAnalisis knn = new KnnAnalisis();
                   
    
        this.jTextArea2.setText(knn.analizarKnn( listaImagenes));
    }//GEN-LAST:event_jButton3ActionPerformed

    
   
    
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrameBuscar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrameBuscar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrameBuscar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrameBuscar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrameBuscar().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    // End of variables declaration//GEN-END:variables
}
